<template>
	<view>
		<uni-list>
			<uni-list :border="true">
				<uni-list-item  :title='item.studentName' :right-text='item.studentPhone' clickable="true"  @click="onPopup(item)"  v-for="item in stuList" class="title">
			
				</uni-list-item>
			</uni-list> 
		</uni-list>
		
		<uni-popup ref="popup" type="dialog" :animation="false" background-color="#fff" is-mask-click='false'>
			<uni-popup-dialog title="编辑学生信息" :before-close="true" @close="close" @confirm="confirm">
				<uni-forms :modelValue="student">
							<uni-forms-item required label="姓名" name="studentName">
								<uni-easyinput type="text" v-model="student.studentName" placeholder="请输入姓名" />
							</uni-forms-item>
							<uni-forms-item required label="手机号" name="studentName">
								<uni-easyinput type="text" v-model="student.studentPhone" placeholder="请输入手机号" />
							</uni-forms-item>
							<uni-forms-item required name="studentName" label="家长手机号">
								<uni-easyinput type="text" v-model="student.parentPhone" placeholder="请输入家长手机号" />
							</uni-forms-item>
						</uni-forms>
			</uni-popup-dialog>
			
		</uni-popup>
	</view>
</template>

<script>
	import student from '@/api/modules/student'
	export default {
		data() {
			return {
				userName: '',
				id: '',
				classId:"",
				className:"",	
				stuList:[],
				student:{
					studentId:"",
					studentName:"",
					studentPhone:"",
					parentPhone:""
				}
			}
		},
		onShow() {
			var that = this
			uni.getStorage({
				key: "loginName",
				success: (res) => {
					that.userName = res.data//获取用户姓名
				}
			})
			uni.getStorage({
				key: "loginId",
				success: (res) => {
					that.id = res.data//获取用户id
				}
			})
			this.topName=this.className+"班",
			this.getStudentList()
		},
		methods: {
			getStudentList(){
				student.studentList(this.classId).then(res=>{
					this.stuList=res.data
				})
			},
			onPopup(obj){
				//将obj信息赋值进去
				this.student.studentName=obj.studentName
				this.student.studentPhone=obj.studentPhone
				this.student.parentPhone=obj.parentPhone
				this.student.studentId=obj.studentId
				//居中弹框
				this.$refs.popup.open('center')
			},
			close() {
			   this.$refs.popup.close()
			},
			confirm() {
				student.upStudent(this.student.studentId,this.student.studentName,this.student.studentPhone,this.student.parentPhone).then(res=>{
					if(res.data==1){
						uni.showToast({
							title: '修改成功',
							icon: "success",
						})
						this.$refs.popup.close();
						this.getStudentList()
					}else{
						uni.showToast({
							title: '修改失败',
							icon: "none",
						})
					}
					 
				})
			  
			}
		},
		onLoad(options) {
			this.classId = options.classId
			this.className=options.className
		}
	}
</script>

<style>
.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	},
	.title{
		font-size: 18rpx;
		font-weight: bolder;
	}
	
</style>
